package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.qiantu.api.entity.FloorBean;
import com.qiantu.api.entity.RoomBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.ui.activity.PanelBingingActivity;
import com.qiantu.phone.ui.activity.PanelQRResultActivity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class PanelQRResultAdapter  extends AppAdapter<Map> {
    public PanelQRResultAdapter(Context context) {
        super(context);
    }
    @NonNull
    @Override
    public PanelQRResultAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PanelQRResultAdapter.ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvFloorName;
        private final RecyclerView roomRecyclerView;
        private final PanelQRResultItemAdapter roomLabelAdapter;

        private ViewHolder() {
            super(R.layout.panel_qr_result_item);
            tvFloorName = findViewById(R.id.tv_floor_name);
            roomRecyclerView = findViewById(R.id.room_recycler_view);
            roomRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            roomLabelAdapter = new PanelQRResultItemAdapter(getContext());
            roomRecyclerView.setAdapter(roomLabelAdapter);
            roomLabelAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
                    Map map = roomLabelAdapter.getItem(position);
                    int index = getViewHolderPosition();
                    ((PanelQRResultActivity) getContext()).gotoPanelBinging(map,index,position);

                }
            });
        }

        @Override
        public void onBindView(int position) {
            Map map = getItem(position);
            tvFloorName.setText(map.get("name").toString());
            roomLabelAdapter.setData((List<Map>) map.get("data"));
        }
    }


}
